import request from '@/utils/request';
import Qs from 'qs';
import { TableListParams } from './data.d';

export async function queryRule(params?: TableListParams) {
  return request('/api/rule', {
    params,
  });
}

export async function removeRule(params: { key: number[] }) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'delete',
    },
  });
}

export async function addRule(params: TableListParams) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'post',
    },
  });
}

export async function updateRule(params: TableListParams) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}

const getRandomuserParams = (params: any) => {
  return {
    pageSize: params.pageSize,
    pageNo: params.current,
    ...params,
  };
};

export async function programList(params: TableListParams) {
  console.log(Qs.stringify(getRandomuserParams(params)));
  return request('/api/program/pageList', {
    method: 'GET',
    headers: {
      Authorization:localStorage.getItem('token'),
    },
    data: Qs.stringify(getRandomuserParams(params)),
  });
}
